package com.one.consumer.order.model;

import com.one.common.model.bean.PayWXBean;
import com.one.common.model.http.NetConstant;
import com.one.common.model.http.base.BaseModel;
import com.one.common.model.http.callback.ObserverOnResultListener;
import com.one.common.view.base.BaseActivity;
import com.one.consumer.common.state.OrderStateDe;
import com.one.consumer.common.state.OrderStateCu;
import com.one.consumer.main.model.item.OrderItem;
import com.one.consumer.order.model.item.OrderDetailItem;
import com.one.consumer.reserve.model.item.CustomItem;
import com.one.consumer.reserve.model.item.ReserveItem;
import com.one.consumer.user.model.item.InvoiceItem;

import java.util.ArrayList;
import java.util.Map;

/**
 * author ：zhulunjun
 * email  ：zhulunjun@qq.com
 * date   ：2018/10/21 下午4:57
 * description ：
 **/
public class OrderModel extends BaseModel<OrderApi> {
    public OrderModel(BaseActivity mActivity) {
        super(OrderApi.class, mActivity, NetConstant.APP_HOST_WORKER);
    }


    /**
     * 获取订单列表
     */
    public void getOrderList(String page, String state, ObserverOnResultListener<ArrayList<OrderItem>> listener) {
        Map<String, String> params = getParams();
        params.put("page", page);
        params.put("order_state", state);
        handleOnResultObserver(mApiService.getOrderList(params), listener);
    }

    /**
     * 搜索订单
     */
    public void searchOrder(String page, String name, ObserverOnResultListener<ArrayList<OrderItem>> listener) {
        Map<String, String> params = getParams();
        params.put("page", page);
        params.put("address_name", name);
        handleOnResultObserver(mApiService.getOrderList(params), listener);
    }

    /**
     * 定制加配---订单列表
     */
    public void getCustomList(String page, ObserverOnResultListener<ArrayList<CustomItem>> listener) {
        Map<String, String> p = getParams();
        p.put("page", page);
        p.put("order_state", OrderStateCu.CONFIRM + "," +
                OrderStateCu.PAY_1 + "," +
                OrderStateCu.PAY_2 + "," +
                OrderStateCu.END);
        handleOnResultObserver(mApiService.customList(p), listener);
    }

    /**
     * 装修订单列表
     */
    public void getDEList(String page, ObserverOnResultListener<ArrayList<ReserveItem>> listener) {
        Map<String, String> p = getParams();
        p.put("page", page);
        p.put("order_type", "1,2");
        p.put("order_state", OrderStateDe.CONFIRM + "," +
                OrderStateDe.PAY_1 + "," +
                OrderStateDe.PAY_2 + "," +
                OrderStateDe.PAY_3 + "," +
                OrderStateDe.END);
        handleOnResultObserver(mApiService.reserveList(p), listener);
    }

    /**
     * 装修获取支付凭证
     */
    public void getPayConfigDE(String orderId, ObserverOnResultListener<PayWXBean> listener) {
        Map<String, String> p = getParams();
        p.put("order_id", orderId);
        p.put("pay_way", "wx");
        handleOnResultObserver(mApiService.getPayConfigDE(p), listener);
    }

    /**
     * 定制加配获取支付凭证
     */
    public void getPayConfigCU(String orderId, ObserverOnResultListener<PayWXBean> listener) {
        Map<String, String> p = getParams();
        p.put("order_id", orderId);
        p.put("pay_way", "wx");
        handleOnResultObserver(mApiService.getPayConfigCustom(p), listener);
    }

    /**
     * 报修订单----取消订单
     */
    public void cancelOrder(String orderId, ObserverOnResultListener<Object> listener) {
        Map<String, String> p = getParams();
        p.put("order_id", orderId);
        handleOnResultObserver(mApiService.cancelOrder(p), listener);
    }

    /**
     * 报修订单----用户接受师傅填写的材料报价 确认订单
     */
    public void confirmOrder(String orderId, ObserverOnResultListener<Object> listener) {
        Map<String, String> p = getParams();
        p.put("order_id", orderId);
        handleOnResultObserver(mApiService.confirmOrder(p), listener);
    }

    /**
     * 订单---评价订单
     */
    public void evaluateOrder(Map<String, String> param, ObserverOnResultListener<Object> listener) {
        Map<String, String> p = getParams();
        p.putAll(param);
        handleOnResultObserver(mApiService.evaluateOrder(p), listener);
    }

    /**
     * 订单----支付订单
     */
    public void payOrder(String orderId, ObserverOnResultListener<PayWXBean> listener) {
        Map<String, String> p = getParams();
        p.put("order_id", orderId);
        p.put("pay_way", "wx");
        handleOnResultObserver(mApiService.payOrder(p), listener);
    }

    /**
     * 订单----删除订单
     */
    public void deleteOrder(String orderId, ObserverOnResultListener<Object> listener) {
        Map<String, String> p = getParams();
        p.put("order_id", orderId);
        handleOnResultObserver(mApiService.deleteOrder(p), listener);
    }

    /**
     * 发票----申请发票
     */
    public void applyInvoice(Map<String,String> param,  ObserverOnResultListener<Object> listener) {
        Map<String, String> p = getParams();
        p.putAll(param);
        handleOnResultObserver(mApiService.applyInvoice(p), listener);
    }

    /**
     * 发票----发票详情
     */
    public void invoiceDetail(String id, ObserverOnResultListener<InvoiceItem> listener) {
        Map<String, String> p = getParams();
        p.put("order_invoice_id", id);
        handleOnResultObserver(mApiService.invoiceDetail(p), listener);
    }

    /**
     * 发票----发票记录
     */
    public void invoiceList(String page, ObserverOnResultListener<ArrayList<InvoiceItem>> listener) {
        Map<String, String> p = getParams();
        p.put("page", page);
        handleOnResultObserver(mApiService.invoiceList(p), listener);
    }


    /**
     * 报修订单----订单详情
     */
    public void orderDetail(String orderId, ObserverOnResultListener<OrderDetailItem> listener) {
        Map<String, String> p = getParams();
        p.put("order_id", orderId);
        handleOnResultObserver(mApiService.orderDetail(p), listener);
    }

}
